import Vue from 'vue'
import vueRouter from 'vue-router'

Vue.use(vueRouter)

import Iview from 'view-design';
Vue.use(Iview);

//默认主体
import bodys from '../../views/Bodys.vue';
//登陆界面
// import signIn from '../components/SignIn.vue'
const signIn = resolve => {
  require.ensure(['../../views/SignIn.vue'],()=>{
    resolve(require('../../views/SignIn.vue'));
  },'demo');
}
//个人信息界面
// import userInfo from '../components/UserInfo.vue'
const userInfo = resolve => {
  require.ensure(['../../views/UserInfo.vue'],()=>{
    resolve(require('../../views/UserInfo.vue'));
  },'demo');
}
//子父界面
import demo from '../components/demo/Demo.vue'
import messageOne from '../components/demo/MessageOne.vue'
import messageTwo from '../components/demo/MessageTwo.vue'
const routes = [
  {path:'',name:'index',component:bodys},
  {path:'/index',name:'index',component: bodys},
  {path: '/signin',name:'signin',component: signIn,beforeEnter:(to,from,next)=>{
          if(sessionStorage.getItem('name')){
              Iview.Message.warning('已登录...');
              setTimeout(()=>{
                  next({name:'userinfo'})
              },1500)
          }else{
              next();
          }
      }},
  {path: '/userinfo',name:'userinfo',component: userInfo,beforeEnter:(to,from,next)=>{
      if(sessionStorage.getItem('name')){
          next();
      }else{
          Iview.Message.warning('请先登录...');
      }
    }},
  {path: '/demo',name:'message',component: demo,children:[
      //设置子路由
      {path:'',name:'demos',components:{
          default:messageTwo,
          'demos':messageOne
        }},
    ]},
  {path:'*',required:'/'}
]

const router = new vueRouter({
    routes,
    mode:'history'
})

export default router
